package com.hengxinguotong.zhihuichengjian.ui.document;

import android.os.Bundle;
import android.webkit.WebView;
import android.widget.RelativeLayout;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Document;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/12/6.
 */

public class ReadDocumentActivity extends BaseActivity {
    @BindView(R.id.title_tv)
    HXTextView titleTv;
    @BindView(R.id.iv_back)
    HXTextView ivBack;
    @BindView(R.id.iv_detail)
    HXTextView ivDetail;
    @BindView(R.id.rl_title)
    RelativeLayout rlTitle;
    @BindView(R.id.webview)
    WebView webview;
    private Document document;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        ButterKnife.bind(this);
        document = (Document) getIntent().getSerializableExtra("document");
        if(document.getName().length() > 12){
            titleTv.setText(document.getName().substring(0, 11) + "...");
        }else{
            titleTv.setText(document.getName());
        }
        String url = null;
        if(!Utils.isEmpty(document.getNameType())){
            switch (document.getNameType()){
                case "jpg":
                case "jpeg":
                case "png":
                case "JPG":
                case "JPEG":
                case "PNG":
                    url = document.getPath().replace("type=2", "type=1");
                    break;
                default:
                    url = document.getPath().replace("type=2", "type=3");
                    break;
            }
        }else {
            url = document.getPath();
        }
        webview.loadUrl(url);
    }
}
